﻿using System;
using System.Collections.Specialized;
using System.Net;
using System.Web;
using FBGraph.Models;

namespace FBGraph.Controllers.Connections.Users
{
    public partial class HomeController
    {
        /// <summary>Performs a search for the specified <paramref name="query" /> against the current user's news feed.</summary>
        /// <param name="query">The keywords to search for.</param>
        /// <returns>A <see cref="PagedResult{Post}" /> containing results of the search.</returns>
        public PagedResult<Post> Search(String query)
        {
            var queryStringValues = new NameValueCollection();
            queryStringValues.Add("q", query);
            var uri = Context.CreateRequestUri("home", queryStringValues, "me");

            var request = (HttpWebRequest)WebRequest.Create(uri);
            var result = Context.Execute<PagedResult<Post>>(new FBGraphApiRequest(request));

            return result;
        }
    }
}